// This file reshapes and labels the allocations

set more off

forvalues i = 30(-1)1 {
    forvalues j = 0/5 {
        local k = `j' + 1
        capture gen tmp`k'Q`i' = dalloc`i'_`j'
        capture gen tmp`k'W`i' = ralloc`i'_`j'
        capture gen tmp`k'V`i' = p3ralloc`i'_`j'
        capture gen tmp`k'P`i' = prices`i'_`j'
        }
    }

// reshape
reshape long tmp1V tmp2V tmp3V tmp4V tmp5V tmp6V tmp1Q tmp2Q tmp3Q tmp4Q tmp5Q tmp6Q tmp1P tmp2P tmp3P tmp4P tmp5P tmp6P tmp1W tmp2W tmp3W tmp4W tmp5W tmp6W dalloc ralloc p3ralloc prices, i(subject) j(pnum)

// problem number
label var pnum "Problem # (1-30)"

// drop empty allocations
drop if mi(dalloc)

// drop wide variables
drop dalloc*_* prices*_* ralloc*_* p3ralloc*_* dalloc p3ralloc prices ralloc
    
// allocations into particular companies
forvalues i = 1/6 {
    ren tmp`i'P price`i'
    ren tmp`i'Q dshares`i'
    ren tmp`i'W rshares`i'
    ren tmp`i'V p2rshares`i'
    label var price`i' "Price of company #`i' for a given pnum"
    label var dshares`i' "CBC allocation"
    label var rshares`i' "Part 1 rule allocation"
    label var p2rshares`i' "Part 2 rule allocation"
}

